
<extend name="Common/common"/>

<block name="content">
<div class="page-container">
	<form action="{:U('NewBlogCat/add')}" method="post" class="form form-horizontal" id="form-user-add">
		
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>上级分类：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<span class="select-box">
				<select name="pid" class="select">
					<option value="0">第一级分类</option>
					<foreach name='list' item='v'>
					<option value="{$v['cat_id']}" <if condition="$v['cat_id']==$res['pid']">selected</if> >{:str_repeat('==',$v['C_count'])}{$v['cat_name']}</option>
					</foreach>
				</select>
				</span>
			</div>
		</div>
		
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				分类名称：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text" name="cat_name" value="{$res['cat_name']}" placeholder="" id="user-name" name="product-category-name">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">排序：</label>
			<div class="formControls col-xs-6 col-sm-1">
				<input type="text" class="input-text" name="sort" value="{$res['sort']}<if condition='empty($res)'>0</if>"  placeholder="" id="user-name" name="product-category-name">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>是否显示：</label>
			<div class="formControls col-xs-6 col-sm-6 skin-minimal">
				<div class="radio-box">
					<input name="is_show" type="radio" value="1" id="sex-1" <if condition='$res["is_show"]==1'>checked</if> <if condition="empty($res)">checked</if> >
					<label for="sex-1">显示</label>
				</div>
				<div class="radio-box">
					<input type="radio" <if condition='$res["is_show"]==="0"'>checked</if> id="sex-2" value="0" name="is_show">
					<label for="sex-2">隐藏</label>
				</div>
			</div>
		</div>
		
		<div class="row cl">
			<div class="col-9 col-offset-1">
				<input type="hidden" name="id" value="{$res['cat_id']}" />
				
				
				<if condition="!empty($res)">
				<input class="btn btn-primary radius" type="button" onclick="updateAction(this)" value="&nbsp;&nbsp;修改分类&nbsp;&nbsp;">
				<input class="btn btn-danger radius" onclick="deleteCat({$res['cat_id']})" type="button" value="&nbsp;&nbsp;删除分类&nbsp;&nbsp;">
				<else/>
				<input class="btn btn-primary radius" type="button" onclick="addAction(this)"  value="&nbsp;&nbsp;添加分类&nbsp;&nbsp;">
				</if>
			</div>
		</div>
	</form>
</div>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
function addAction(obj){
	
	$(obj).append($('<input type="hidden" name="is_add" value="1">'));
	$("form:first").submit();
}

function updateAction(obj){
	$(obj).append($('<input type="hidden" name="is_add" value="0"/>'));
	$('form:first').submit();
}
function deleteCat(id){
	
	$.post("{:U('NewBlogCat/delete')}",{id:id},function (data){
		
		if(data == 1){ // 删除成功
			alert('删除成功');
			parent.location.reload();
		}else { // 删除失败
			alert('删除失败，请稍后重试');
		}
		
	});
	
}

$(function(){
	
	
	
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	$("#form-user-add").validate({
		rules:{
			username:{
				required:true,
				minlength:2,
				maxlength:16
			},
			sex:{
				required:true,
			},
			mobile:{
				required:true,
				isMobile:true,
			},
			email:{
				required:true,
				email:true,
			},
			uploadfile:{
				required:true,
			},
			
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		
	});

});
</script>
</block>